/**
 * Created by Administrator on 2017/8/29.
 */
var pageSize=10;
var pages=0;
var cont=1;
var time=Date.parse(new Date())/1000;
console.log(time);
function getActi() {
    $.ajax({
        type : "GET",
        url : getRequestUrl("/activity/get"),
        dataType : 'json',
        async: true,
        data:{
            user_id:"1",
            page_size:pageSize,
            type:2,
            page_num:1,
            timestamp:time
        },
        // contentType : "application/json",
        success : function(datas) {
            console.log(datas);
            //soll=true;
            var arr=datas.response_params.result;
            pages=datas.response_params.total_cnt;
            var strs="";
            $.each(arr,function (i,el) {
                strs+=`<div class="m-market-activity" data-id=`+arr[i].activity_id+` onclick="getAcInfo(this)">
                            <div class="content">
                                <div class="progress `+C(arr[i].activity_status)+`">`+Wz(arr[i].activity_status)+`</div>
                                    <div class="imgbox" style="background-image: url(`+arr[i].logo_url[0]+`)">
                                    
                                         <div class="activitytoux-box">
                                            <img src=`+arr[i].portiait+`>
                                        </div>
                                    </div>
                                <div>
                                    <div class="t-activitymame">
                                        <div class="line-x"></div>
                                        <div>`+arr[i].nick_name+`</div>
                                      
                                    </div>
                                    <div class="activityrqf">
                                        <div>人数:`+arr[i].person_cnt+`人</div>
                                        <div>预计费用:`+arr[i].cost+`元</div>
                                        <div>付款方式:`+arr[i].cost_desc+`</div>
                                    </div>
                                </div>
                            </div>
                        </div>`
            });
            $(strs).appendTo("#list");

            $("#loading").hide();

        },
        error : function(err) {
        	dealCPErrorResponse(err);
        }
    });
}
getActi();
function C(s) {
    if(s=="1"){
        return "in"
    }else {
        return "";
    }
}
function Wz(s) {
    if(s=="1"){
        return "报名中"
    }else {
        return "已结束";
    }
}
function gcscroll(obj) {
    var $this =$(obj),
        viewH =$this.height(),//可见高度
        contentH =$this.get(0).scrollHeight,//内容高度
        scrollTop =$this.scrollTop();//滚动高度
    if(contentH - viewH - scrollTop <=1) { //到达底部100px时,加载新内容
        //console.log(cont);
        var nowpage=pages%pageSize==0?(pages/pageSize):(Math.floor(pages/pageSize)+1);
        if(nowpage===cont){

            return
        }
        //alert("1111")
        cont+=1;
        console.log(cont)
        showToast();
        xlgetActi()
    }
}

function xlgetActi() {
    $.ajax({
        type : "GET",
        url : getRequestUrl("/activity/get"),
        dataType : 'json',
        async: true,
        data:{
            user_id:"1",
            page_size:pageSize,
            type:2,
            page_num:cont,
            timestamp:time
        },
        // contentType : "application/json",
        success : function(datas) {
            console.log(datas);
            //soll=true;
            var arr=datas.response_params.result;
            pages=datas.response_params.total_cnt;
            var strs="";
            $.each(arr,function (i,el) {
                strs+=`<div class="m-market-activity" data-id=`+arr[i].activity_id+` onclick="getAcInfo(this)">
                            <div class="content">
                                <div class="progress `+C(arr[i].activity_status)+`">`+Wz(arr[i].activity_status)+`</div>
                                    <div class="imgbox" style="background-image: url(`+arr[i].logo_url[0]+`)">
                                    
                                         <div class="activitytoux-box">
                                            <img src=`+arr[i].portiait+`>
                                        </div>
                                    </div>
                                <div>
                                    <div class="t-activitymame">
                                        <div class="line-x"></div>
                                        <div>`+arr[i].nick_name+`</div>
                                       
                                    </div>
                                    <div class="activityrqf">
                                        <div>人数:`+arr[i].person_cnt+`人</div>
                                        <div>预计费用:`+arr[i].cost+`元</div>
                                        <div>付款方式:`+arr[i].cost_desc+`</div>
                                    </div>
                                </div>
                            </div>
                        </div>`
            });
            $(strs).appendTo("#list");
            hideToast();

        },
        error : function(err) {
        	dealCPErrorResponse(err);
        }
    });
}
function showToast() {
    $("#loadingToast").show()
}
function hideToast() {
    $("#loadingToast").hide();
}
function getAcInfo(obj){
    var $this=$(obj);
    var id=$this.attr("data-id");
    window.location.href="activitiesing.html?id="+id;
}
function getActivity() {
    $.ajax({
        type : "GET",
        url : getRequestUrl("/activity/get_type"),
        dataType : 'json',
        async: true,
        success : function(datas) {
            console.log(datas);
            if(datas.response_params.result!=0){
                var arr=datas.response_params.result;
                var strs="";
                $.each(arr,function (i,e) {
                    strs+=`<input type="button"  data-id=`+arr[i].activity_id+`   value=`+arr[i].activity_name+` onclick="addClass(this)">`
                });
                $(strs).appendTo("#hdlx");
                $("#loading").hide();
            }

        },
        error : function(err) {
        	dealCPErrorResponse(err);
        }
    });
}
$(function () {
    getActivity();
})
function addClass(obj) {
    var $this=$(obj);
    var id=$this.attr("data-id");
    $this.addClass("active").siblings().removeClass("active");
    $("#hdlxyc").val(id);

}
function addClass2(obj) {
    var $this=$(obj);
    var id=$this.attr("data-id");
    $this.addClass("active").siblings().removeClass("active");
    $("#hdsjyc").val(id);
}

//点击筛选后加载的内容
function sxbtn() {
    $.ajax({
        type : "GET",
        url : getRequestUrl("/activity/get"),
        dataType : 'json',
        async: true,
        data:{
            user_id:"1",
            page_size:100,
            type:2,
            page_num:1,
            activity_type_id:$("#hdlxyc").val(),
            dis_start_time:$("#hdsjyc").val(),
            timestamp:time
        },
        // contentType : "application/json",
        success : function(datas) {
            console.log(datas);
            //soll=true;
            $("#list").html("");
            var arr=datas.response_params.result;
            pages=datas.response_params.total_cnt;
            var strs="";
            $.each(arr,function (i,el) {
                strs+=`<div class="m-market-activity" data-id=`+arr[i].activity_id+` onclick="getAcInfo(this)">
                            <div class="content">
                                <div class="progress `+C(arr[i].activity_status)+`">`+Wz(arr[i].activity_status)+`</div>
                                    <div class="imgbox" style="background-image: url(`+arr[i].logo_url[0]+`)">
                                    
                                         <div class="activitytoux-box">
                                            <img src=`+arr[i].portiait+`>
                                        </div>
                                    </div>
                                <div>
                                    <div class="t-activitymame">
                                        <div class="line-x"></div>
                                        <div>`+arr[i].nick_name+`</div>
                                       
                                    </div>
                                    <div class="activityrqf">
                                        <div>人数:`+arr[i].person_cnt+`人</div>
                                        <div>预计费用:`+arr[i].cost+`元</div>
                                        <div>付款方式:`+arr[i].cost_desc+`</div>
                                    </div>
                                </div>
                            </div>
                        </div>`
            });
            $(strs).appendTo("#list");

            //$("#loading").hide();

        },
        error : function(err) {
        	dealCPErrorResponse(err);
        }
    });
}